package system

import (
	"context"

	"admin_template/bff/admin/hertz_gen/base"
	genSysCaptcha "admin_template/bff/admin/hertz_gen/system/sys_captcha"
	"admin_template/bff/admin/internal/pkg/utils"
	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
)

type CaptchaRepo interface {
	Get() (*genSysCaptcha.Info, error)
	Verify(dataID string, captcha string) bool
}

type CaptchaService struct {
	*Service
}

func NewCaptchaService(s *Service) *CaptchaService {
	return &CaptchaService{s}
}

// Get .
// @router /v1/system/captcha [GET]
func (s *CaptchaService) Get(ctx context.Context, c *app.RequestContext) {
	captchaInfo, err := s.captchaRepo.Get()
	if err != nil {
		utils.ReplyWithErr(c,
			ctx,
			"captchaRepo GET",
			"",
			s.CtxLogger, err)
		return
	}
	reply := genSysCaptcha.GetReply{
		Code: base.ErrCode_Success,
		Msg:  "成功",
		Data: &genSysCaptcha.InfoData{Info: captchaInfo},
	}
	utils.Reply(c, consts.StatusOK, &reply)
}
